package com.example.practical_training_projects.controller;

import com.example.practical_training_projects.entity.askform;
import com.example.practical_training_projects.entity.questionform;
import com.example.practical_training_projects.service.askformService;
import com.example.practical_training_projects.service.questionformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin //允许跨域执行
@RequestMapping("askform")
public class askformController {
    @Autowired
    private askformService service;

    /**
     * GET http://localhost:8080/askform/list 显示
     * POST http://localhost:8080/askform/add 添加
     * GET http://localhost:8080/askform/del/{{a_uid}} 删除
     * POST http://localhost:8080/askform/update 更新
     * GET http://localhost:8080/askform/get/{{a_uid}} 获取
     * @return
     */

    @GetMapping("list")
    public List<askform> getAllAF(){
        return service.getAllAF();
    }

    @PostMapping("add")
    public Integer insertAF(@RequestBody askform af) {
        //@RequestBody能接收转换的字符串，并匹配到StudentInfo studentInfo中
        return service.insertAF(af);
    }
    @GetMapping("/del/{a_uid}")
    public  Integer deleteAF(@PathVariable("a_uid") Integer af){
        return service.deleteAF(af);
    }
    @PostMapping("update")
    public Integer updateAF(@RequestBody askform af){
        return service.updateAF(af);
    }
    @GetMapping("/get/{a_uid}")
    public questionform findAFuid(@PathVariable("a_uid") Integer a_uid) {
        return service.findAFuid(a_uid);
    }

    @GetMapping("/getByQUid/{q_uid}")
    public List<askform> getAskFormsByQUid(@PathVariable("q_uid") Integer q_uid) {
        return service.getAskFormsByQUid(q_uid);}


}
